package com.minhua.jijiehao2.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.jaeger.library.StatusBarUtil;
import com.minhua.jijiehao2.utils.ActivityTaskManager;


/**
 * @author moo
 * @date 2017/11/3.
 * @describe MVP activity基类
 */

public abstract class BaseActivity<V, P extends BaseMvpPresenter<V>> extends AppCompatActivity {
    protected P mPresenter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityTaskManager.getActivityTaskManager().createActivity(this);
        setStatusBar();
        setContentView(getLayoutId());
        mPresenter = getPresenter();
        if (mPresenter != null) {
            mPresenter.attach((V) this);
        }
        initView();
        initData();
    }

    protected void setStatusBar() {
        StatusBarUtil.setTranslucentForImageView(this, null);
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        ActivityTaskManager.getActivityTaskManager().destroyActivity(this);
        if (mPresenter != null) {
            mPresenter.detach();
        }
    }

    /**
     * 获取资源文件id
     *
     * @return 资源文件id
     */
    protected abstract int getLayoutId();

    /**
     * 获取该页面的Presenter
     *
     * @return Presenter实例
     */
    protected abstract P getPresenter();


    /**
     * 初始化界面
     */
    protected abstract void initView();

    /**
     * 初始化数据（某些不用则不需要重写）
     */
    protected void initData() {
    }
}
